app.register.controller('homeCtrl',['$scope','$location', '$http','$cookies', function ($scope,$location,$http,$cookies) {
    //页面数据
    $scope.hometype = 'jingxuanid';
    $scope.bordershow = 1;
    $scope.navrighthidd = 0;
    
    
    //获取精选的数据
    $http({
        method:'POST',
        url:$config.host+'/api/Events/EventIndex',
    }).success(function (data) {
        // console.log(JSON.stringify(data));
        if(data.nFlag==1){
            $scope.choiceeventlist = data.data.choiceeventlist;
            $scope.maxMemberEventList = data.data.maxMemberEventList;
            $scope.beginningEventList = data.data.beginningEventList;
        }else{
            $scope.popShow(data.strMessage);
        }
    })

    // 获取不同类型id的数据
    $http({
        method:'POST',
        url:$config.host+'/api/events/GetEventCategoryList',
    }).success(function (data) {
        // console.log(JSON.stringify(data));
        if(data.nFlag==1){
            $scope.eventCategoryList = data.data.eventCategoryList;

        }else{
            $scope.popShow(data.strMessage);
        }
    })

    //角标背景色
    $scope.gobgcolor = function (index) {
        var txt,num = index%4;
        if(num==0){
            txt = 'taggreen';
        }else if(num==1){
            txt = 'tagblue';
        }else if(num==2){
            txt = 'tagred';
        }else{
            txt = 'tagyellwo';
        }
        return txt;
    }



    //选项卡
    var page, isListLock = true;
    $scope.gonCategoryId = function (cid,index) {
        // console.log(cid,index);
        page=1;
        $scope.bordershow = cid;
        if(index){
            $scope.hometype = 'qitaid';
            getListData();
        }else{
            $scope.hometype = 'jingxuanid';
        }
    }

    //请求接口
    function getListData() {
        if(!isListLock) return;
        isListLock = false;
        //根据不同的id类型取到不同数据
        $http({
            method:'POST',
            url:$config.host+'/api/Events/GetActivityType',
            params:{
                nCategoryId : $scope.bordershow,
                nCurPage : page,
            }
        }).success(function (data) {
            // console.log(JSON.stringify(data));
            if(data.nFlag==1){
                if(page==1){
                    $scope.homePage = data.data.homePage;
                }else{
                    $scope.homePage = $scope.homePage.concat(data.data.homePage)
                }
                if(data.nCurPage==data.nMaxPage){
                    page=false;
                }else{
                    page++;
                }
            }else{
                $scope.popShow(data.strMessage);
            }
            //解锁
            isListLock = true;
        })
    }

    //滚动到底部
    window.onscroll = function () {
        if($config.isScrollBottom(100)&&page>0){
            getListData();
        }
    }
}]);